Page({
  data: {
    currentTab: 0,
    categories: [
      { id: 1, name: "数码电子", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/数码电子.jpg", customPage: "shumadianzi" },
      { id: 2, name: "家用电器", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/家用电器.jpg" },
      { id: 3, name: "服装帽子", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/服装.jpg" },
      { id: 4, name: "家具家居", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/家具家居.jpg" },
      { id: 5, name: "美妆个护", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/美妆个护.jpg" },
      { id: 6, name: "图书文娱", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/图书.jpg" },
      { id: 7, name: "交通工具", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/交通.jpg" },
      { id: 8, name: "虚拟物品", icon: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/虚拟.jpg" }
    ],
    products: [
      { id: 1, price: 35, seller: "小明", image: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/包.jpg" },
      { id: 2, price: 40, seller: "大米", image: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/杯.jpg" },
      { id: 3, price: 15, seller: "玲玲", image: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/桌.jpg" },
      { id: 4, price: 60, seller: "李华", image: "cloud://cloud1-4g6id6dg2ae9b3aa.636c-cloud1-4g6id6dg2ae9b3aa-1376791391/手机.jpg" }
    ]
  },

  onLoad: function(options) {
    // 页面初始化逻辑
  },

  onCategoryTap: function(e) {
    const category = this.data.categories.find(item => item.id === e.currentTarget.dataset.id);
    
    if (category.customPage) {
      wx.navigateTo({
        url: `/pages/${category.customPage}/${category.customPage}`
      });
    } else {
      wx.navigateTo({
        url: `/pages/category/category?id=${category.id}`
      });
    }
  },

  onProductTap: function(e) {
    const productId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/detail/detail?id=${productId}`
    });
  },

  switchTab: function(e) {
    const tab = parseInt(e.currentTarget.dataset.tab);
    if (tab === 0) {
      return;
    }
    
    this.setData({
      currentTab: tab
    });
    
    const pages = ['/pages/index/index', '/pages/publish/publish', 
                  '/pages/message/message', '/pages/profile/profile'];
    wx.switchTab({
      url: pages[tab]
    });
  }
});